﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace David.Framework.Core.Extensions
{
    public static class ExceptionExtension
    {
        public static string GetMessage(this Exception target)
        {
            if (target != null)
            {
                return GetExceptionMsg(target) + " 跟踪信息:" + target.StackTrace;
            }

            return "";
        }

        private static string GetExceptionMsg(Exception ex)
        {
            string msg = ex.Message;

            if (ex.InnerException != null)
            {
                msg += "内部信息：" + GetExceptionMsg(ex.InnerException);
            }

            return msg;
        }
    }
}
